import { http } from "@/utils/http";

export interface IParamsForList {
  pageSize: number;
  pageNum: number;
  eqpIdOrName?: string;
  className?: string;
  ruleTypeCode?: string;
}

export interface IRuleSettingItem {
  id: number;
  ruleTypeCode: string;
  ruleTypeName: string;
  className: string;
  classNameDesc: string;
  eqpName: string;
  eqpId: string;
  runStatusPoint: string;
  runStatusName: string;
  runStatusFormula: string;
  awaitStatusPoint: string;
  awaitStatusName: string;
  awaitStatusFormula: string;
  offlineStatusPoint: string;
  offlineStatusName: string;
  offlineStatusFormula: string;
  diseaseStatusPoint: string;
  diseaseStatusName: string;
  diseaseStatusFormula: string;
  faultStatusPoint: string;
  faultStatusName: string;
  faultStatusFormula: string;
  meterCoerceStatusPoint: string;
  meterCoerceStatusName: string;
  meterCoerceStatusFormula: string;
  sideSupplyStatusPoint: string;
  sideSupplyStatusName: string;
  sideSupplyStatusFormula: string;
  updateName: string;
  updateTime: string;
}

export type ResponseDataForSettingList = {
  data: IRuleSettingItem[];
  pageNum: number;
  pageSize: number;
  pages: number;
  total: number;
};

export interface IRuleSetting {
  id: number;
  eqpId: string;
  ruleTypeCode: string;
  runRule: {
    isEnabled: boolean;
    eqpRunStatusPointList: string[];
    formula: string;
  };
  faultRule: {
    isEnabled: boolean;
    eqpRunStatusPointList: string[];
    formula: string;
  };
  diseaseRule: {
    isEnabled: boolean;
    eqpRunStatusPointList: string[];
    formula: string;
  };
  offlineRule: {
    isEnabled: boolean;
    eqpRunStatusPointList: string[];
    formula: string;
  };
  awaitRule: {
    isEnabled: boolean;
    eqpRunStatusPointList: string[];
    formula: string;
  };
}
export type PartialRuleSetting = Partial<IRuleSetting>;
export type ResponseDataForTypeList = Pick<IRuleSettingItem, "id" | "ruleTypeCode" | "ruleTypeName">;
export type RuleSettingDetail = PartialRuleSetting & {
  ruleTypeName: string;
  eqpName: string;
  className: string;
  classNameDesc: string;
  systemCode: string;
  systemName: string;
  positionCode: string;
  positionName: string;
  positionNameAll: string;
};

// 查询规则说明列表
export const getListForSetting = (data: IParamsForList) => {
  return http.request<ResponseDataForSettingList>("post", "/digitaltwins/api/v1/equipmentStatusRule/queryListPage", { data });
};

export const addRuleForSetting = (data: PartialRuleSetting) => {
  return http.request("post", "/digitaltwins/api/v1/equipmentStatusRule/saveStatusRule", { data });
};

export const updateRuleForSetting = (data: PartialRuleSetting) => {
  return http.request("post", "/digitaltwins/api/v1/equipmentStatusRule/updateStatusRule", { data });
};

export const deleteRuleForSetting = (id: IRuleSettingItem["id"]) => {
  return http.request("post", `/digitaltwins/api/v1/equipmentStatusRule/delStatusRule/${id}`);
};

export const getRuleInfoForSetting = (id: IRuleSettingItem["id"]) => {
  return http.request<RuleSettingDetail>("post", `/digitaltwins/api/v1/equipmentStatusRule/getStatusRule/${id}`);
};

// 导入
export const importRules = (data?: object) => {
  return http.request(
    "post",
    "/digitaltwins/api/v1/equipmentStatusRule/importData",
    {
      data
    },
    {
      headers: {
        "Content-type": "multipart/form-data"
      }
    }
  );
};
